Skip to content

testing/libc/inetntop: Add a test of inet_ntop() - #4024

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:apps-inet-ntop-test-up
Nov 12, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:apps-inet-ntop-test-up

Conversation

@casaroli

@casaroli casaroli commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

No test in nuttx-apps checks inet_ntop(). This PR adds testing/libc/inetntop. It converts 25 IPv6 addresses with inet_ntop(AF_INET6) and compares the text with the recommended form of RFC 5952:

  • :: only for the longest run of two or more 0 fields, the first one on a tie (1::2:0:0:3:4, 1:0:0:2::3), and no :: for one 0 field (1:0:2:3:4:5:6:7, 2001:db8:0:1:1:1:1:1).
  • lowercase hexadecimal.
  • the dotted-decimal IPv4 form for an IPv4-mapped address (::ffff:127.0.0.1, ::ffff:0.0.0.0) and an IPv4-compatible address (::1.2.3.4), but not for ::, ::1, ::102, ::fffe:102:304, 1::ffff:102:304 or 64:ff9b::c000:221.

Each case, and 4 AF_INET cases, also checks the size of the buffer: the call succeeds with strlen() + 1 bytes and fails with ENOSPC with strlen() bytes.

The program prints PASS or FAIL for each case and returns the number of errors. It needs IPv4 and IPv6 address conversions (NET_IPv4/NET_IPv6 or LIBC_IPv4_ADDRCONV/LIBC_IPv6_ADDRCONV).

Impact

New test only, default n like the other tests in testing/libc. No change to other code.

Testing

The expected texts are the glibc 2.43 results: the same source built on fedora x86_64 against glibc passes all 29 cases.

EXTRAFLAGS="-Wno-cpp -Werror", nuttx master 03aea786390 vs the nuttx PR, with LIBC_IPv4_ADDRCONV, LIBC_IPv6_ADDRCONV and TESTING_INETNTOP:

Configuration nuttx master nuttx PR
qemu-armv8a:knsh (kernel, arm64, QEMU HVF; the test is an ELF program in /system/bin) 37 errors 0 errors
qemu-armv8a:nsh (flat, arm64, QEMU HVF) 37 errors 0 errors
qemu-armv8a:nsh, CMake not run 0 errors

On master the 37 errors are 28 ENOSPC with a buffer that fits and 9 wrong texts. ostest: status 0 in all runs. No warnings. tools/checkpatch.sh -c -u -m -g origin/master..HEAD passes.

No test in nuttx-apps checks inet_ntop().  This test converts IPv6
addresses with inet_ntop(AF_INET6) and compares the text with the
recommended form of RFC 5952: "::" only for the longest run of two or
more 0 fields (the first one on a tie), no "::" for one 0 field, and
lowercase hexadecimal.  The IPv4-mapped address (::ffff:127.0.0.1) and
the IPv4-compatible address (::1.2.3.4) end in the dotted-decimal form;
:: and ::1 do not.  glibc gives the same text for each case.

Each case also checks the size of the buffer, for AF_INET6 and AF_INET:
the call succeeds with strlen() + 1 bytes and fails with ENOSPC with
strlen() bytes.

The program prints PASS or FAIL for each case and returns the number of
errors.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli marked this pull request as ready for review November 11, 2026 19:21
@xiaoxiang781216
xiaoxiang781216 merged commit c2073a9 into apache:master Nov 12, 2026
39 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants